package edu.hku.c3330.hkucompanion.manager;
public class Duration 
{
	public void setMillisecond(int millisecond) {
		this.millisecond = millisecond;
	}

	public void setSecond(int second) {
		this.second = second;
	}

	public void setMinute(int minute) {
		this.minute = minute;
	}

	public void setHour(int hour) {
		this.hour = hour;
	}

	public void setDate(int date) {
		this.date = date;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int millisecond, second, minute, hour, date, month, year;
	
	public Duration()
	{
		this(0,0,0,0,0,0,0);
	}
	
	public Duration(int millisecond, int second, int minute, int hour, int date, int month, int year)
	{
		setDuration(millisecond,second,minute,hour,date,month,year);
	}
	
	public int getMillisecond() {
		return millisecond;
	}

	public int getSecond() {
		return second;
	}

	public int getMinute() {
		return minute;
	}

	public int getHour() {
		return hour;
	}

	public int getDate() {
		return date;
	}

	public int getMonth() {
		return month;
	}

	public int getYear() {
		return year;
	}

	public Duration(long rep)
	{
		setLongRep(rep);
	}
		
	public long getLongRep()
	{
		long rep = 0;
		long temp = 1000;
		
		rep += millisecond;
		
		rep += second * temp;
		temp *= 60;
		rep += minute * temp;
		temp *= 60;
		rep += hour * temp;
		temp *= 24;
		rep += date * temp;
		
		return rep;
	}
	public void setLongRep(long rep)
	{
		

		long temp = 3600 * 24 * 1000;
		long mod = rep % temp;	
		long lrep = rep - mod;
		date = (int) (lrep / temp);
		
		lrep = mod;
		temp /= 24;
		mod = lrep % temp;	
		lrep -= mod;
		hour = (int) (lrep / temp);
		
		lrep = mod;
		temp /= 60;
		mod = lrep % temp;	
		lrep -= mod;
		minute = (int) (lrep / temp);
		
		lrep = mod;
		temp /= 60;
		mod = lrep % temp;	
		lrep -= mod;
		second = (int) (lrep / temp);
		
		millisecond = (int)mod;
	}

	public void setDuration(int millisecond, int second, int minute, int hour, int date, int month, int year)
	{
		this.millisecond = millisecond;
		this.second = second;
		this.minute = minute;
		this.hour = hour;
		this.date = date;
		this.month = month;
		this.year = year;
	}
	
}
